<?php 
## include required files
/*******************************/
require_once '../../includefiles.php';
include_once("../../model/users.php");
require_once '../../model/state.php';
require_once '../../redirect.php';



$stateObj = new Model_State();
$userObj = new Model_Users();

checkUserLogin();

$userId = $_SESSION['getbids_id'];

$userDetArray = $userObj->getUserDetailsByUserId($userId);
$smarty->assign('userDetArray',$userDetArray);
$getpostalcodedetail = $stateObj->getPostalcodeExits($userDetArray['workarea']);
$smarty->assign('getpostalcodedetail',$getpostalcodedetail);

if($userDetArray['state_id'] != ""){
$State_array = $stateObj->getStateDetailsById($userDetArray['state_id']);
$smarty->assign('State_array',$State_array);
}

if($_GET['companyname'] !='')
{
	$companyname=str_replace("_"," ",$_GET['companyname']);
	$userdetail = $userObj->getUserDetailsByCompanyName($companyname);
	$userid = $userdetail['id'];	
	$getuserdetail = $userObj->getUserDetailsByUserId($userid);
	
	/*if($getuserdetail['tradeid']!='')
	{
		$getTradecat = $tradeObj->getTradeCategoryDetailsById($getuserdetail['tradeid']);	
		$getuserdetail['trade_name'] = $getTradecat['trade_category'];
	}*/
	
	if($getuserdetail['workarea']!='')
	{
		$getpostaldetail = $stateObj->getPostalCodeDetailsByPostalId($getuserdetail['workarea']);
		$getuserdetail['suburbname'] = $getpostaldetail['suburb'];
	}
	
	if($getpostaldetail['state']!='')
	{
		$getstatedetail = $stateObj->getStateDetailsByISOCODE($getpostaldetail['state']);
		$getuserdetail['statename'] = $getstatedetail['state_name'];
		$getuserdetail['stateid'] = $getstatedetail['state_id'];
		
		$getallpostalcode = $stateObj->getAllSuburb($getpostaldetail['state']);
					
			for($i=0;$i<count($getallpostalcode);$i++)
			{
				$getallpostalcode_arr[] ="'".$getallpostalcode[$i]["postcode"]."'";
			}
			if($getallpostalcode_arr[0]!='')
				$implodearray = @implode(",",$getallpostalcode_arr);
			else
				$implodearray = 0;	
				
			$postalcode = $implodearray; 
	}
	
	$userreviewcount=$userObj->getUserRatingCount($getuserdetail['id']);	
	$getuserdetail['userreviewcount'] =$userreviewcount['cnt']	;
			
	$userAllleadcount = $userObj->getleadcountofTradesmanByUserId($getuserdetail['id']);	
	if($userAllleadcount['cnt']!='0' && $userreviewcount['cnt']	!='0')
	{
			$positive =( $userreviewcount['cnt']/$userAllleadcount['cnt'] ) *100;
			$getuserdetail['positive'] =  number_format($positive,2);
	}
	else
		$getuserdetail['positive'] = 0;
		
	
	$userlastreviewdetail=$userObj->getUserLastReviewDetail($getuserdetail['id']);	
	if($userlastreviewdetail['job_id']!='')
	{
		$getjobdetail=$userObj->getJobDetailsById($userlastreviewdetail['job_id']);	
		$getuserdetail['userlastreview_trade_category'] = $getjobdetail['trade_category'];
		$getuserdetail['userlastreview_job_desc'] = $getjobdetail['job_desc'];
	}			
	$getuserdetail['userlastreview_feedback'] =$userlastreviewdetail['message'];
	$getuserdetail['userlastreview_username'] =$userlastreviewdetail['first_name']." ".$userlastreviewdetail['last_name'];
	$getuserdetail['userlastreview_added_date'] =$userlastreviewdetail['added_date'];
	if($userlastreviewdetail['added_date']!='')
	{
		$timestamp = strtotime($userlastreviewdetail['added_date']);
	
		$getuserdetail['userlastreview_added_date_suffix'] = date('S', $timestamp);
	}
	

	$userreviewdetail=$userObj->getUserAllReviewDetail($getuserdetail['id']);	
	for($i=0;$i<count($userreviewdetail);$i++)
	{
		if($userreviewdetail[$i]['job_id']!='')
		{
			$getjobdetail=$userObj->getJobDetailsById($userreviewdetail[$i]['job_id']);	
			$userreviewdetail[$i]['userlastreview_trade_category'] = $getjobdetail['trade_category'];
			$userreviewdetail[$i]['userlastreview_job_desc'] = $getjobdetail['job_desc'];
		}			
		if($userreviewdetail[$i]['added_date']!='')
		{
			$timestamp = strtotime($userreviewdetail[$i]['added_date']);
		
			$userreviewdetail[$i]['userlastreview_added_date_suffix'] = date('S', $timestamp);
		}
	}
	$smarty->assign('userreviewdetail', $userreviewdetail);	

	
	if($getuserdetail['id']!='')
	{
		$userworkphotodetail=$userObj->getAllWorkPhotoByUserID($getuserdetail['id']);	
		//echo "<pre>";print_R($userworkphotodetail);die();
		$smarty->assign('userworkphotodetail', $userworkphotodetail);		
	}
	
	$topTradesjobs= $userObj->gettopthreeTradesjobs();	
	$smarty->assign('topTradesjobs', $topTradesjobs);
	
	$relatedTradesjobs= $userObj->getrelatedTradesjobs($postalcode);	
	$smarty->assign('relatedTradesjobs', $relatedTradesjobs);
	
	$smarty->assign('user_details', $getuserdetail);
}



if($_SESSION['msg'] != ''){
	$smarty->assign("msg", $_SESSION['msg']);	
	unset($_SESSION['msg']);
}

if($_SESSION['error'] != ''){
	$smarty->assign("errorMsg", $_SESSION['error']);	
	unset($_SESSION['error']);
}

$active = "myaccount";
$smarty->assign("active", $active);
$smarty->assign("subactive", $active);
$smarty->assign('mainmenu', '1');

if($_SESSION['user_type'] == '3')
	$smarty->display(TEMPLATEDIR.'/modules/myaccount/myaccount_home.tpl');
else
	$smarty->display(TEMPLATEDIR.'/modules/myaccount/myaccount.tpl');
unset($smarty);
?>
